/**
 * @filename:UserController 2023年03月24日
 * @project cloud_dev  V1.0
 * Copyright(c) 2020 shangtf Co. Ltd. 
 * All right reserved. 
 */
package com.cloud.work.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.service.Contact;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>自动生成工具：mybatis-dsc-generator</p>
 * Swagger核心配置文件
 * ========================
 * @author shangtf 
 * @Date   2023年03月24日
 * ========================
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
	
	@Value("true")
    private Boolean swagger_enable;
	
	public static String SWAGGER_TITLE="API文档-shangtf-测试"; 	    		//Swagger接口文档标题
	public static String SWAGGER_DESCRIPTION="API文档";   				//Swagger接口文档描述
	public static String SWAGGER_VERSION="1.0";                         //Swagger接口文档版本
	public final static String SWAGGER_URL="http://127.0.0.1:9527";    //Swagger项目服务的URL

	/**
	 * 创建API
	 * http:ip:端口号/swagger-ui/index.html   原生地址
	 * http:ip:端口号/doc.html   bootStrap-Ui地址
	 */
	@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30).pathMapping("/")
				//用来创建该api的基本信息，展示在文档的页面中（自定义展示的信息）
				.apiInfo(apiInfo())
				//设置哪些接口暴露给swagger展示
				.select()
				//扫描所有有注解的api，用这种方式更灵活
				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
				//扫描指定包中的swagger注解
				//.apis(RequestHandlerSelectors.basePackage("com.xx"))
				//扫描所有   .apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.regex("(?!/ApiError.*).*"))
				.paths(PathSelectors.any())
				.build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
				//设置标题
                .title(SWAGGER_TITLE)
				//描述
                .description(SWAGGER_DESCRIPTION)
				//作者信息
				.contact(new Contact("shangtf-测试说明！", null,null))
                .termsOfServiceUrl(SWAGGER_URL)
				//版本
                .version(SWAGGER_VERSION)
                .build();
    }
}
